var maxDepth = function(root) {//用递归
    if(!root)return 0
    let left=maxDepth(root.left)
    let right=maxDepth(root.right)
    return Math.max(left,right)+1
    
    };

 
var maxDepth = function(root) {//用递归
    const res=[],queue=[root]
       if(!root)return res
       while(queue.length){
           let len=queue.length,temp=[]
           for(let i=1;i<=len;i++){
               let node=queue.shift()
               temp.push(node.val)
               node.left&&queue.push(node.left)
               node.right&&queue.push(node.right)
           }
           res.push(temp)
       }
          return res.length
   };